package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.*;
	public class OldPhotoAction extends AbstractAction
	{
		private var fade:Number;
		public function setValue(fade:Number):OldPhotoAction
		{
			this.fade = fade;
			return this;
		}
		
		public override function getDescription():String
		{
			return "Old Photo (" + this.fade.toFixed(0) +  " )";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			
			var colorMatrixFilter:ColorMatrixFilter = new ColorMatrixFilter();
			colorMatrixFilter.matrix = new Array(1 / 2, 1 / 2, 1 / 2, 0, 0, 1 / 3, 1 / 3,
									 1 / 3, 0, 0, 1 / 4, 1 / 4, 1 / 4, 0, 0, 0, 0, 0, 1, 0);
			
			ret.applyFilter(ret, ret.rect, new Point(0, 0), colorMatrixFilter);
			ret.merge(old, ret.rect, new Point(0,0), 256 - fade,
				256 - fade, 256 - fade, 256 - fade);
			return ret;
		}	
	}
}